<?php

namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\Models\Family;

/**
 * Class FamilyTransformer.
 *
 * @package namespace App\Transformers;
 */
class FamilyTransformer extends TransformerAbstract
{
    /**
     * Transform the Family entity.
     *
     * @param \App\Models\Family $model
     *
     * @return array
     */
    public function transform(Family $model)
    {
        return [
            'id'         => (int) $model->id,
            'company' => $model->company,
            'name' => $model->name,
            'id_card' => $model->id_card . "&nbsp;",
            'staff_name' => $model->staff->name,
            'staff_dorm' => optional($model->staff->dorm)->code,
            'relationship' => $model->relationship,
            'dorm_type' => $model->dorm_type,
            'age' => $model->age,
            'sex' => $model->sex ? ($model->sex == 1 ? '男' : '女') : '',
            'status' => $model->status == 1 ? '寄宿' : '搬出',
            'phone' => $model->phone . "&nbsp;",
            'remark' => $model->remark,
            'created_at' => $model->created_at->format('Y-m-d H:i:s'),
            'updated_at' => $model->updated_at->format('Y-m-d H:i:s')
        ];
    }
}
